/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import models.Aluno;

/**
 *
 * @author User
 */
public class AlunoDB {

    private Connection connection = null;

    public boolean inserir(Aluno aluno) {
        boolean inseriu = false;
        connection = Conexao.getInstance().getConnection();
        PreparedStatement stmt = null;
        try {

            stmt = this.connection.prepareStatement("INSERT INTO alunos (nome, cpf, email, telefone, endereco) VALUES (?, ?, ?, ?, ?)");
            stmt.setString(1, aluno.getNome());
            stmt.setString(2, aluno.getCpf());
            stmt.setString(3, aluno.getEmail());
            stmt.setString(4, aluno.getTel());
            stmt.setString(5, aluno.getEndereco());
            stmt.executeUpdate();

            inseriu = true;
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        } finally {
            try {
                stmt.close();
                connection.close();
            } catch (SQLException e) {
                System.out.println("Erro ao desconectar" + e.getMessage());
            }
        }
        return inseriu;
    }
}
